<?php
date_default_timezone_set('Europe/London');


$data = explode('/',$_SERVER['REQUEST_URI']);

//[REQUEST_URI] => /draftrack/FE/public/ressources/apidefinition/copeo_membre.jpg
//print_r($data);

//Filenma is the last one of the URI
$fileName = array_pop($data);

//We check how it finish, must be css|jpg|gif|png|js
$explodedFile = explode('.',$fileName);
$fileType = array_pop($explodedFile);

$mime = '';
switch ($fileType) {
    case 'js':
        $mime = 'application/x-javascript';
        break;
    case 'png':
        $mime = 'image/png';
        break;
    case 'css':
        $mime = 'text/css';
        break;
    case 'jpg':
        $mime = 'image/jpeg';
        break;
    case 'gif':
        $mime = 'image/gif';
        break;
}

if(empty($mime)) {
header("HTTP/1.0 404 Not Found");
exit;	
}

//The URL should be something like

$ressourcesPartFound = false;
$path = '';
$moduleName = '';
foreach($data as $num => $part) {

  if($ressourcesPartFound) {
  	//The moduleName must be just after the ressources part
  	if(empty($moduleName)) $moduleName = $part;
    else $path .= $part.'/';
  }

  if('ressources' == $part) $ressourcesPartFound = true;
}

if(!$ressourcesPartFound) {
  header('HTTP/1.0 404 Not Found');
  exit;		
}

//ressource should be there: app/src/modules/apidefinition/ressources/copeo_membre.png


$res = @file_get_contents('../app/src/modules/'.$moduleName.'/ressources/'.$path.$fileName);
if($res) {
  header('Content-type: '.$mime);
  echo $res;
}
else{
  header('HTTP/1.0 404 Not Found');
  exit;	
}



?>